/**
 *  实现原理： 就是把浮点数变成整型,运算完以后再变成浮点数
 *
 */
// 自己实现
const toFixed = (num, n) => {
    return parseInt(((num * (Math.pow(10, n))) + 0.5), 10) / Math.pow(10, n)
}
// 两个浮点数求和
const Add = (num1, num2) => {
    let r1, r2, m
    try {
        r1 = `${num1}`.split('.')[1].length
    } catch (e) {
        r1 = 0
    }
    try {
        r2 = `${num2}`.split('.')[1].length
    } catch (e) {
        r2 = 0
    }
    m = Math.pow(10, Math.max(r1, r2))
    console.log(Math.max(r1,r2));
    console.log(m)
    return Math.round(num1 * m + num2 * m) / m
}
// 两个浮点数相减
const Sub = (num1, num2) => {
    let r1, r2, m, n
    try {
        r1 = `${num1}`.split('.')[1].length
    } catch (e) {
        r1 = 0
    }
    try {
        r2 = `${num2}`.split('.')[1].length
    } catch (e) {
        r2 = 0
    }
    m = Math.pow(10, Math.max(r1, r2))
    n = (r1 >= r2) ? r1 : r2
    return toFixed((Math.round(num1 * m - num2 * m) / m), n)
}
// 两个浮点数相乘
const Mul = (num1, num2) => {
    let m = 0, s1 = `${num1}`, s2 = `${num2}`
    try {
        m += s1.split('.')[1].length
    } catch (e) { }
    try {
        m += s2.split('.')[1].length
    } catch (e) { }
    console.log('m',m);
    console.log('s1:',s1);
    console.log('s1-replace:',Number(s1.replace('.', '')));
    return Number(s1.replace('.', '')) *
        Number(s2.replace('.', '')) /
        Math.pow(10, m)
}
// 两个浮点数相除
const Div = (num1, num2) => {
    let t1, t2, r1, r2
    try {
        t1 = `${num1}`.split('.')[1].length
    } catch (e) {
        t1 = 0
    }
    try {
        t2 = `${num2}`.toString().split('.')[1].length
    } catch (e) {
        t2 = 0
    }
    r1 = Number(`${num1}`.replace('.', ''))
    r2 = Number(`${num2}`.toString().replace('.', ''))
    return (r1 / r2) * Math.pow(10, t2 - t1)
}

// console.log(toFixed(1.55,1));
// console.log(toFixed(2.55,1));
// console.log(toFixed(3.55,1));
// console.log(toFixed(4.55,1));
// console.log(toFixed(5.55,1));
// console.log(toFixed(6.55,1));
// console.log(toFixed(7.55,1));
// console.log(toFixed(8.55,1));
// console.log(toFixed(9.55,1));

// console.log(0.3+0.6);
console.log(Mul(1.33,2.23));


